/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.dialogs;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JComboBox;
import javax.swing.JPanel;

import br.ufmg.dees.insane.commons.dialogs.SimpleDialog;
import br.ufmg.dees.insane.model.disc.analysismodel.AxiSymetricAnalysisM;
import br.ufmg.dees.insane.model.disc.analysismodel.PlaneStrainAnalysisM;
import br.ufmg.dees.insane.model.disc.analysismodel.PlaneStressAnalysisM;
import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;

/**
 * A class representing creation dialog on screen.
 * For example:
 * <pre>
 *    ElmAnalysisModelDialog dgl = new ElmAnalysisModelDialog(parent);
 *    dgl.pack();
 * </pre>
 *
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @see gui.InsaneInternalInterface
 * @since April 2004
 */
public final class ElmAnalysisModelDialog extends SimpleDialog {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private InsaneInternalInterface parent;
	private FemModel fmodel;
	
	private String[] analysisTypeStr;
	private JComboBox analysisTypeCombo;
	public String anlTypeChosen;
	
//*****************************************************************************
	
	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see gui.InsaneInternalInterface
	 */
	public ElmAnalysisModelDialog(InsaneInternalInterface parent) {
		this.parent = parent;
		fmodel = parent.getModel().getDiscreteModel();
		
		if (!(fmodel.getGlobalAnalysisModel().getType().equals("Grid"))) {
			analysisTypeStr = new String[3];
			analysisTypeStr[0] = parent.getResourceBundle().getString("dGAnlDialog01");
			analysisTypeStr[1] = parent.getResourceBundle().getString("dGAnlDialog02");
			analysisTypeStr[2] = parent.getResourceBundle().getString("dGAnlDialog03");
		} else {
			analysisTypeStr = new String[1];
			analysisTypeStr[0] = parent.getResourceBundle().getString("dGAnlDialog04");
		}
		if((fmodel.getGlobalAnalysisModel() instanceof PlaneStrainAnalysisM)|| 
		   (fmodel.getGlobalAnalysisModel() instanceof PlaneStressAnalysisM)||
		   (fmodel.getGlobalAnalysisModel() instanceof AxiSymetricAnalysisM)){
			analysisTypeStr = new String[4];
			analysisTypeStr[0] = parent.getResourceBundle().getString("dGAnlDialog07");
			analysisTypeStr[1] = parent.getResourceBundle().getString("dGAnlDialog08");
			analysisTypeStr[2] = parent.getResourceBundle().getString("dGAnlDialog09");
			analysisTypeStr[3] = parent.getResourceBundle().getString("dGAnlDialog03");
		}
		analysisTypeCombo = new JComboBox(analysisTypeStr);
		setUpFields();
		
		JPanel mainPane = new JPanel();
		mainPane.setPreferredSize(new Dimension(200,35));
		mainPane.setLayout(new GridLayout(1,1,2,2));
		analysisTypeCombo.setPreferredSize(new Dimension (180,26));
		JPanel subPane = new JPanel();
		subPane.add(analysisTypeCombo);
		mainPane.add(subPane);
		
		setPane(mainPane);
		
    }
	
//*****************************************************************************
	
    public int showDialog() {
    	return super.showDialog(parent, parent.getResourceBundle().getString("dGAnlDialog06"));
    }
	
//*****************************************************************************
	
	/**
	 * This method is executed on OK button click.
	 */
	public void approvedPerform() {
		
		try {
			int anlIndex = analysisTypeCombo.getSelectedIndex();
			anlTypeChosen = analysisTypeStr[anlIndex];
		} catch (Exception e) {
			Toolkit.getDefaultToolkit().beep();
			this.setVisible(false);
		}
	}
	
//*****************************************************************************
	
	/**
	 * Sets up fields
	 */
	private void setUpFields() {
		
		//Checking if it's possible to choose an analysis model for the element different
		//from the global analysis model
		if (fmodel.getGlobalAnalysisModel().getType().equals("Beam")) {
			analysisTypeCombo.setSelectedIndex(0);
			analysisTypeCombo.setEnabled(false);
		} else if (fmodel.getGlobalAnalysisModel().getType().equals("PlaneFrame")) {
			analysisTypeCombo.setSelectedIndex(1);
			analysisTypeCombo.setEnabled(true);
		} else if (fmodel.getGlobalAnalysisModel().getType().equals("PlaneTruss")) {
			analysisTypeCombo.setSelectedIndex(2);
			analysisTypeCombo.setEnabled(false);
		} else if (fmodel.getGlobalAnalysisModel().getType().equals("Grid")) {
			analysisTypeCombo.setSelectedIndex(0);
			analysisTypeCombo.setEnabled(false);
		}else if (fmodel.getGlobalAnalysisModel() instanceof PlaneStressAnalysisM ) {
			analysisTypeCombo.setSelectedIndex(0);
			analysisTypeCombo.setEnabled(true);
		}else if (fmodel.getGlobalAnalysisModel() instanceof PlaneStrainAnalysisM){
		    analysisTypeCombo.setSelectedIndex(1);
			analysisTypeCombo.setEnabled(true);
		}else if (fmodel.getGlobalAnalysisModel() instanceof AxiSymetricAnalysisM){
		    analysisTypeCombo.setSelectedIndex(2);
			analysisTypeCombo.setEnabled(true);
		}
		
	}
	
//*****************************************************************************
}

